<template>
  <Layout>
    <Form ref="form1" :model="form1" :label-width="120">
      <Row v-show="!switchFlag" class="query-form" style="padding-top: 15px">
        <Col span="8">
          <FormItem label="伤亡人员姓名：">
            <Input type="text" v-model="form1.victim"></Input>
          </FormItem>
        </Col>
        <Col span="8">
          <FormItem label="伤害程度：">
            <Select v-model="injuryLevels" multiple>
              <Option v-for="item in injuryLeveList" :value="item.codingCodeId" :key="item.codingCodeId">
                {{ item.codingName }}
              </Option>
            </Select>
          </FormItem>
        </Col>
        <Col span="8">
          <Button @click="switchQuery(true)" class="ivu-btn-switch" type="text">展开∨</Button>
          <Button @click="reset" class="ivu-btn-reset">重置</Button>
          <Button class="ivu-btn-query" icon="md-search" @click="query()">查询</Button>
        </Col>
      </Row>
      <Row v-show="switchFlag" class="query-form" style="padding-top: 15px">
        <Col span="8">
          <FormItem label="伤亡人员姓名：">
            <Input type="text" v-model="form1.victim"></Input>
          </FormItem>
        </Col>
        <Col span="8">
          <FormItem label="伤害程度：">
            <Select v-model="injuryLevels" multiple>
              <Option v-for="item in injuryLeveList" :value="item.codingCodeId" :key="item.codingCodeId">
                {{ item.codingName }}
              </Option>
            </Select>
          </FormItem>
        </Col>
        <Col span="8">
          <FormItem label="就业类型：">
            <Select v-model="memberships" multiple>
              <Option v-for="item in membershipList" :value="item.codingCodeId" :key="item.codingCodeId">
                {{ item.codingName }}
              </Option>
            </Select>
          </FormItem>
        </Col>
      </Row>
      <Row v-show="switchFlag" class="query-form" style="padding-top: 15px">

        <Col span="8" offset="16">
          <Button @click="switchQuery(false)" class="ivu-btn-switch" type="text">收起∧</Button>
          <Button @click="reset" class="ivu-btn-reset">重置</Button>
          <Button class="ivu-btn-query" icon="md-search" @click="query">查询</Button>
        </Col>
      </Row>
      <Row class="query-form">
        <Col span="24">
          <Button size="large" class="ivu-btn-add" icon="md-add" @click="addInfo">新增</Button>
        </Col>
      </Row>
    </Form>
    <Table ref='table' :height="tableHeight" :loading="loading" size="small" class="table" no-data-text="没有查询到相关数据!"
           highlight-row stripe border :columns="columns1" width="100%" :data="dataTable">
    </Table>
    <Row style="margin-right:10px;">
      <Col span="24">
        <Page :total="pagedata.total" :page-size="pagedata.pageSize" @on-change="pageChange"
              style="float: right" @on-page-size-change="pageSizeChange" :page-size-opts="pageSizeArray"
              show-total show-sizer show-elevator/>
      </Col>
    </Row>

    <Modal :transfer=false :mask-closable="false" v-model="model1" :width=700 :title="add?'安全事故报告书新增':'安全事故报告书修改'"
           @on-cancel="onCancel">
      <div>
        <Form ref='InputData' :model="InputData" :rules="ruleCustom" label-position="top">
          <Row type="flex" justify="space-around" class="code-row-bg">
            <Col span='23'>
              <FormItem label="伤亡人员姓名：" prop="briefId">
                <Input v-model="InputData.victim" placeholder="请选择伤亡人员姓名" :readonly="true">
                  <Button slot="append" @click="openForSelect" icon="ios-search"></Button>
                </Input>
              </FormItem>
            </Col>
          </Row>
          <Row type="flex" justify="space-around" class="code-row-bg">
            <Col span='11'>
              <FormItem label="就业类型：" prop="membershipName">
                <Input v-model="InputData.membershipName" :readonly="true"/>
              </FormItem>
            </Col>
            <Col span='11'>
              <FormItem label="伤害程度：" prop="injuryLevelName">
                <Input v-model="InputData.injuryLevelName" :readonly="true"/>
              </FormItem>
            </Col>
          </Row>
          <Row type="flex" justify="space-around" class="code-row-bg">
            <Col span='23'>
              <FormItem label='事故报告简述：' prop="reportDesc">
                <Input v-model="InputData.reportDesc" type="textarea" :autosize="{minRows:2,maxRows:5}"/>
              </FormItem>
            </Col>

          </Row>
          <Row type="flex" justify="space-around" class="code-row-bg">
            <Col span="23">
              <FormItem label="事故报告书：">
                <div>
                  <Upload ref="upload"
                          :before-upload="beforeUpload"
                          :show-upload-list="true"
                          :max-size="10240"
                          multiple
                          type="drag"
                          :action="fileUrl">
                    <div style="padding: 10px">
                      <Icon type="ios-cloud-upload" size="45" style="color: #3399ff"></Icon>
                      <p>点击将文件拖拽到这里上传</p>
                      <span style="font-size:8px;color: #797a64">支持扩展名：.rar .zip .doc .docx .pdf...</span>
                    </div>
                  </Upload>
                </div>
                <div v-show="uploadList.length>0" v-for="(item,index) in uploadList" :key='item'>
                  <a @click="downloadFile(InputData.reportId,item,index)">{{ item.fileName }}</a>
                  <Button type="text" icon="md-trash" @click="remove1(item.id)"
                          style="margin-left: 5px;margin-bottom: 3px"/>
                  <Progress  v-show="uploadListVisible[index]" :percent="uploadListPercent[index]"></Progress>
                </div>
              </FormItem>
            </Col>
          </Row>
          <!-- <Row type="flex" justify="center" class="code-row-bg">
               <Col span="23">
                   <FormItem>
                       <Button class='ivu-btn-save' :loading="buttonLoading" @click="submit('InputData')">确定</Button>
                       <Button class='ivu-btn-cancel' @click="onCancel">取消</Button>
                   </FormItem>
               </Col>
           </Row>-->
        </Form>
      </div>
      <div slot="footer">
        <Button class='ivu-btn-save' :loading="buttonLoading" @click="submit('InputData')">确定</Button>
        <Button class='ivu-btn-cancel' @click="onCancel">取消</Button>
      </div>
    </Modal>

    <Modal :transfer=false v-model="model3" :width=700 title="安全事故报告书详情" @on-cancel="onCancel">
      <Form :model="InputData" label-position="top">
        <div style="line-height: 42px;margin-left: 20px">
          <Row>
            <Col span='11'>
              <span>伤亡人员姓名：{{ InputData.victim }}</span>
            </Col>
            <Col span='11' offset="1">
              <span>工种或岗位：{{ InputData.position }}</span>
            </Col>
          </Row>
          <Row class="detail-background-clor">
            <Col span='11'>
              <span>事故时间：{{ InputData.sartDateStr }}</span>
            </Col>
            <Col span='11' offset="1">
              <span>事故类别：{{ InputData.accTypeName }}</span>
            </Col>
          </Row>
          <Row>
            <Col span='11'>
              <span>就业类型：{{ InputData.membershipName }}</span>
            </Col>
            <Col span='11' offset="1">
              <span>伤害程度：{{ InputData.injuryLevelName }}</span>
            </Col>
          </Row>
          <Row class="detail-background-clor">
            <Col span='11'>
              <span>创建人：{{ InputData.userName }}</span>
            </Col>
            <Col span='11' offset="1">
              <span>创建时间：{{ InputData.createDate }}</span>
            </Col>
          </Row>
          <Row>
            <Col span='23'>
              <span>事故报告简述：{{ InputData.reportDesc }}</span>
            </Col>
          </Row>
          <Row class="detail-background-clor">
            <Col span="23">
              <FormItem label="事故报告书：">
                <div v-show="uploadList.length>0" v-for="(item,index) in uploadList" :key='item'>
                  <a @click="downloadFile(InputData.briefId,item,index)">{{ item.fileName }}</a>
                  <Progress  v-show="uploadListVisible[index]" :percent="uploadListPercent[index]"></Progress>
                </div>
              </FormItem>
            </Col>
          </Row>
        </div>
      </Form>
      <div slot="footer">
        <Button class='ivu-btn-save' @click="onCancel">关闭</Button>
      </div>
    </Modal>

    <Modal title="事故简报" :transfer=false footer-hide v-model="briefingList" :width=900>
      <FollowReportForSelect @getSelectData="getSelectData">
      </FollowReportForSelect>
    </Modal>

    <Modal :transfer=false v-model="model4" :width=900>
      <Tabs>
        <TabPane label="历史记录">
          <Table ref='table1' border :columns="columns2" no-data-text="没有查询到相关数据！" style="margin-top: 0"
                 :loading="loading2"
                 :data="history" width="100%" :height="450" highlight-row stripe size="small"></Table>
        </TabPane>
        <TabPane label="流程图">
          <div style="height: 450px; overflow-y: auto; overflow-x: auto">
            <img :src="imgUrl">
          </div>
        </TabPane>
      </Tabs>
      <div slot="footer">
        <Button @click="model4=false" class="ivu-btn-save">关闭</Button>
      </div>
    </Modal>
    <Modal title="事故报告书上报" v-model="model5" :width=500>
      <Spin fix v-if="spinShow">
        <Icon type="ios-loading" size=18 class="demo-spin-icon-load"></Icon>
        <div>表单信息加载中，请稍后</div>
      </Spin>
      <Form ref="dataToView" label-position="top" :model="dataToView" :rules="ruleCustomReport">
        <Row :gutter="16">
          <Col span='24'>
            <FormItem label="企业负责人：" prop="chargeId">
              <Select v-model="dataToView.chargeId">
                <Option v-for="item in chargeList" :value="item.userId" :key="item.userId">
                  {{ item.userName }}
                </Option>
              </Select>
            </FormItem>
          </Col>
        </Row>
        <Row :gutter="16">
          <Col span='24'>
            <FormItem label="二级集团安全环保管理人员：" prop="secondaryGroupPersionId">
              <Select v-model="dataToView.secondaryGroupPersionId">
                <Option v-for="item in secondaryGroupPersionList" :value="item.userId" :key="item.userId">
                  {{ item.userName }}
                </Option>
              </Select>
            </FormItem>
          </Col>
        </Row>
        <Row :gutter="16" v-if="groupCompany">
          <Col span='24'>
            <FormItem label="集团安全环保管理人员：" prop="groupPersionId">
              <Select v-model="dataToView.groupPersionId">
                <Option v-for="item in groupPersionList" :value="item.userId" :key="item.userId">
                  {{ item.userName }}
                </Option>
              </Select>
            </FormItem>
          </Col>
        </Row>
      </Form>
      <div slot="footer">
        <Button class='ivu-btn-save' :loading="buttonLoading" @click="submitReport('dataToView')">上报</Button>
        <Button class='ivu-btn-cancel' @click="model5=false;">取消</Button>
      </div>
    </Modal>
  </Layout>
</template>

<script>
import {Api} from '../../../../api/index.js'
import {sessionStorage} from '../../../../common/cacheUtils.js';
import FollowReportForSelect from '../followReport/followReportForSelect';
import cascaderDom from "../../../../components/cascader-dom.vue"

export default {
  name: "interestedPartiesBlack",
  components: {FollowReportForSelect, cascaderDom},
  data() {
    return {
      ruleCustomReport: {
        chargeId: [{
          validator: (rule, value, callback) => {
            if (value == null || value == '' || value == undefined) {
              callback(' ')
            } else {
              callback()
            }
          },
          required: true,
          trigger: 'change'
        }],
        groupPersionId: [{
          validator: (rule, value, callback) => {
            if (value == null || value == '' || value == undefined) {
              callback(' ')
            } else {
              callback()
            }
          },
          required: true,
          trigger: 'change'
        }],
        secondaryGroupPersionId: [{
          validator: (rule, value, callback) => {
            if (value == null || value == '' || value == undefined) {
              callback(' ')
            } else {
              callback()
            }
          },
          required: true,
          trigger: 'change'
        }],
      },
      uploadListVisible:[],
      uploadListPercent:[],
      currentUser:sessionStorage('userId').getObject('userId'),
      spinShow: false,
      loading2: false,
      history: [],
      imgUrl: "",
      briefingList: false,
      uploadList: [],
      tableHeight: '',
      dataToView: {},
      loading: false,
      form1: {
        admittanceOrg: '',
        contractorName: '',
      },
      sexList: [
        {
          value: '0',
          text: '男'
        },
        {
          value: '1',
          text: '女'
        }
      ],
      groupCompany: false,
      model5: false,
      groupPersionList: [],
      secondaryGroupPersionList: [],
      chargeList: [],
      injuryLevels: [],
      memberships: [],
      pageSizeArray: [10, 20, 50],
      pagedata: {
        total: 0,
        pageSize: 10,
        currentPage: 1,
      },
      model4: false,
      dataTable: [],
      appesaseList: [],
      ruleCustom: {
        reportDesc: [{
          message: '  ',
          required: true,
          trigger: 'blur'
        }],

        membershipName: [{
          validator: (rule, value, callback) => {
            if (this.InputData.membershipName == null || this.InputData.membershipName == '' || this.InputData.membershipName == undefined) {
              callback(' ')
            } else {
              callback()
            }
          },
          required: true,
          trigger: 'change'
        }],
        injuryLevelName: [{
          validator: (rule, value, callback) => {
            if (this.InputData.injuryLevelName == null || this.InputData.injuryLevelName == '' || this.InputData.injuryLevelName == undefined) {
              callback(' ')
            } else {
              callback()
            }
          },
          required: true,
          trigger: 'change'
        }],
        briefId: [{
          validator: (rule, value, callback) => {
            if (value == null || value == '' || value == undefined) {
              callback(' ')
            } else {
              callback()
            }
          },
          required: true,
          trigger: 'change'
        }],

      },
      columns2: [
        {
          type: 'index',
          title: '序号',
          width: 80,
          align: 'center',
        },
        {
          width: 180,
          title: '审批时间',
          key: 'endTime',
          align: 'center',
        },
        {
          width: 185,
          title: '节点名称',
          key: 'name',
          align: 'center',
        },
        {
          width: 120,
          title: '审批人',
          key: 'userName',
          align: 'center'
        },
        {
          width: 100,
          title: '审批意见',
          key: 'route',
          align: 'center'
        },
        {
          width: 200,
          title: '备注',
          key: 'opinions',
          align: 'center'
        },
      ],
      columns1: [
        {
          title: "序号",
          width: 80,
          align: "center",
          fixed: 'left',
          render: (h, params) => {
            return h('span', params.index + (this.pagedata.currentPage - 1) * this.pagedata.pageSize + 1);
          }
        },
        {
          title: '伤亡人员姓名',
          align: 'center',
          key: 'victim',

        },
        {
          title: '伤害程度',
          align: 'center',
          key: 'injuryLevelName',

        },
        {
          title: '就业类型',
          align: 'center',
          key: 'membershipName',

        },
        {
          title: '工种或岗位',
          align: 'center',
          key: 'position',

        },
        {
          title: '事故时间',
          align: 'center',
          key: 'sartDateStr',
        },
        {
          title: '事故类别',
          align: 'center',
          key: 'accTypeName',

        },
        {
          title: '事故报告简述',
          align: 'center',
          key: 'reportDesc',
          tooltip: true

        },
        {
          title: "审批状态",
          width: 100,
          align: "center",
          fixed: 'right',
          render: (h, params) => {
            return h('div', [
              h('span', {
                style: {
                  color: params.row.procinstState == '0' ? 'red' : params.row.procinstState == 1 ? 'green' : params.row.procinstState == 2 ? 'orange' : params.row.procinstState == 3 ? 'blue' : 'red'
                },
              }, params.row.procinstState == '0' ? '未上报' : params.row.procinstState == 1 ? '审批中' : params.row.procinstState == 2 ? '被退回' : params.row.procinstState == 3 ? '审批完成' : '未上报' || '未上报')
            ]);
          }
        },
        {
          title: '操作',
          key: 'action',
          fixed: 'right',
          width: 280,
          align: 'center',
          render: (h, params) => {
            if (params.row.procinstState == undefined || params.row.procinstState == null) {
              if (this.currentUser.loginId === this.Common.admin || this.currentUser.userId === params.row.createUserId || this.currentUser.userRole.find(obj => obj.roleId == '73b38b37dff64392ba0ee7dd579bf293') != undefined
                      ||this.currentUser.userBeHandedOver.find(obj => obj == params.row.createUserId) != undefined){
                return h('div', [
                  h('A', {
                    props: {
                      type: 'primary',
                      size: 'small'
                    },
                    style: {
                      fontSize: '14px',
                    },
                    on: {
                      click: () => {
                        this.InputData = JSON.parse(JSON.stringify(params.row));
                        this.getFiles();
                        this.model3 = true;
                      }
                    }
                  }, '详情'),
                  h('Divider', {
                    props: {
                      type: 'vertical',
                    }
                  }, ''),
                  h('A', {
                    props: {
                      type: 'primary',
                      size: 'small'
                    },
                    style: {
                      fontSize: '14px',
                    },
                    on: {
                      click: () => {
                        this.dataToView.workId = params.row.reportId;
                        this.dataToView.briefId = params.row.briefId;
                        if (params.row.injuryLevels == '1000001019000000003') {
                          this.groupCompany = true;
                        } else {
                          this.groupCompany = false;
                        }
                        this.model5 = true;


                      }
                    }
                  }, '上报'),
                  h('Divider', {
                    props: {
                      type: 'vertical',
                    }
                  }, ''),
                  h('A', {
                    props: {
                      type: 'primary',
                      size: 'small'
                    },
                    style: {
                      fontSize: '14px',
                    },
                    on: {
                      click: () => {

                        this.InputData = JSON.parse(JSON.stringify(params.row));
                        this.model1 = true;
                        this.getFiles();
                        this.add = false

                      }
                    }
                  }, '修改'), h('Divider', {
                    props: {
                      type: 'vertical',
                    }
                  }, ''),
                  h('A', {
                    props: {
                      type: 'error',
                      size: 'small'
                    },
                    style: {
                      fontSize: '14px',
                      color: 'red',
                    },
                    on: {
                      click: () => {
                        this.$Modal.confirm({
                          title: '提示',
                          content: '<p>是否要删除？</p>',
                          onOk: () => {
                            this.deleteData(params.row);
                          },
                          onCancel: () => {
                          }
                        });
                      }
                    }
                  }, '删除'),
                  h('Divider', {
                    props: {
                      type: 'vertical',
                    }
                  }, ''),
                  h('A', {
                    props: {type: 'primary', size: 'small'},
                    style: {fontSize: '14px', color: '#c5c8ce', pointerEvents: 'none'},
                  }, '审批记录')
                ]);
              }else{
                return h('div', [
                  h('A', {
                    props: {
                      type: 'primary',
                      size: 'small'
                    },
                    style: {
                      fontSize: '14px',
                    },
                    on: {
                      click: () => {
                        this.InputData = JSON.parse(JSON.stringify(params.row));
                        this.getFiles();
                        this.model3 = true;
                      }
                    }
                  }, '详情'),
                  h('Divider', {
                    props: {
                      type: 'vertical',
                    }
                  }, ''),
                  h('A', {
                    props: {type: 'primary', size: 'small'},
                    style: {fontSize: '14px', color: '#c5c8ce', pointerEvents: 'none'},
                  }, '上报'),
                  h('Divider', {
                    props: {
                      type: 'vertical',
                    }
                  }, ''),
                  h('A', {
                    props: {type: 'primary', size: 'small'},
                    style: {fontSize: '14px', color: '#c5c8ce', pointerEvents: 'none'},
                  }, '修改'),
                  h('Divider', {
                    props: {
                      type: 'vertical',
                    }
                  }, ''),
                  h('A', {
                    props: {type: 'primary', size: 'small'},
                    style: {fontSize: '14px', color: '#c5c8ce', pointerEvents: 'none'},
                  }, '删除'),
                  h('Divider', {
                    props: {
                      type: 'vertical',
                    }
                  }, ''),
                  h('A', {
                    props: {
                      type: 'primary',
                      size: 'small'
                    },
                    style: {
                      fontSize: '14px',
                    },
                    on: {
                      click: () => {
                        this.imgUrl = Api.getFlowImg + '/' + params.row.procinstId;
                        this.showHistory(params.row);

                      }
                    }
                  }, '审批记录')
                ]);
              }

            } else {
              return h('div', [
                h('A', {
                  props: {
                    type: 'primary',
                    size: 'small'
                  },
                  style: {
                    fontSize: '14px',
                  },
                  on: {
                    click: () => {
                      this.InputData = JSON.parse(JSON.stringify(params.row));
                      this.getFiles();
                      this.model3 = true;
                    }
                  }
                }, '详情'),
                h('Divider', {
                  props: {
                    type: 'vertical',
                  }
                }, ''),
                h('A', {
                  props: {type: 'primary', size: 'small'},
                  style: {fontSize: '14px', color: '#c5c8ce', pointerEvents: 'none'},
                }, '上报'),
                h('Divider', {
                  props: {
                    type: 'vertical',
                  }
                }, ''),
                h('A', {
                  props: {type: 'primary', size: 'small'},
                  style: {fontSize: '14px', color: '#c5c8ce', pointerEvents: 'none'},
                }, '修改'),
                h('Divider', {
                  props: {
                    type: 'vertical',
                  }
                }, ''),
                h('A', {
                  props: {type: 'primary', size: 'small'},
                  style: {fontSize: '14px', color: '#c5c8ce', pointerEvents: 'none'},
                }, '删除'),
                h('Divider', {
                  props: {
                    type: 'vertical',
                  }
                }, ''),
                h('A', {
                  props: {
                    type: 'primary',
                    size: 'small'
                  },
                  style: {
                    fontSize: '14px',
                  },
                  on: {
                    click: () => {
                      this.imgUrl = Api.getFlowImg + '/' + params.row.procinstId;
                      this.showHistory(params.row);

                    }
                  }
                }, '审批记录')
              ]);
            }

          }
        }
      ],
      add: false,
      InputData: {deptLeaderId: '', deptLeaderName: ''},
      locationSurveyList: [],

      buttonLoading: false,
      banStart: '',
      banEnd: '',
      pageModel2: {
        total: 0,
        pageSize: 10,
        currentPage: 1,
        contractorName: ''
      },
      switchFlag: false,
      contractor: [],
      model2: false,
      model1: false,
      model3: false,
      membershipList: [],
      typeList: [],
      injuryLeveList: [],
      fileUrl: Api.interestedPartiesUserFile,

    }
  },
  mounted() {
    this.tableHeight = window.innerHeight - this.$refs.table.$el.offsetTop - 145;
    this.getCompanyId();
    this.query()
    this.selectCodingSort();
  },
  methods: {
    switchQuery(flag) {
      this.switchFlag = flag;
      if (!this.switchFlag) {
        this.tableHeight = this.tableHeight + 44;
      } else {
        this.tableHeight = this.tableHeight - 44;
      }
    },


    openForSelect() {
      this.briefingList = true;
    },
    getSelectData(row) {
      this.InputData.briefId = row.briefId;
      this.InputData.victim = row.victim;
      this.InputData.membershipName = row.membershipName;
      this.InputData.injuryLevelName = row.injuryLevelName;

      this.briefingList = false;
    },
    sendMessage(userId){
      let data = {userId: userId, content: "您有一条事故报告需要审批，请登录安全环保信息平台进行审批" };
      this.$http.post(Api.sendMessage, data);
    },
    remindComplete(workId){
      this.$http.get(Api.remindComplete+"/"+workId);
    },
    submitReport(name) {
      let _this = this;
      this.$refs[name].validate((valid) => {
        if (valid) {

          let user = sessionStorage('userId').getObject('userId')
          _this.buttonLoading = true;
          let data = {
            createUserId: user.userId,
            userName: user.userName,
            workId: _this.dataToView.workId,
            user1: _this.dataToView.chargeId,
            user2: _this.dataToView.secondaryGroupPersionId,
          };
          if (_this.groupCompany){
            data.type = "sgbg3";
            data.formKey = "reportListForApproval";
            data.user3 = _this.dataToView.groupPersionId;
            data.key = "reportList3";
          }else{
            data.type = "sgbg2";
            data.formKey = "reportListForApproval";
            data.key = "reportList2";
          }
          _this.$http.post(Api.submit, data).then(function (res) {
            _this.buttonLoading = false;
            if (res.data.status == 200){
              _this.sendMessage(data.user1);
              _this.remindComplete(_this.dataToView.briefId);
              _this.$Message.success({
                content: '上报成功',
                duration: 4
              });
            }
            _this.model5 = false;
            _this.query();
          }, function (err) {
            _this.buttonLoading = false;
            _this.model5 = false;
            _this.$Message.error({
              content: '上报失败',
              duration: 4
            });
          });
        } else {
          this.$Message.error('请填报完整!');
        }
      });
    },
    async getCompanyId() {
      this.spinShow = true;
      await this.$http.get(Api.queryRoleUser + "/" + "cfb951f2448f44a6ba805e1d5313fa75", {params: {orgId: sessionStorage('userId').getObject('userId').companyId}}).then((res) => {
        this.chargeList = res.data.data;
      }).catch(e => {
        this.$Message.error("数据获取失败")
      });
      //二级集团
      await this.$http.get(Api.queryRoleUser + "/" + "843197356dd443d099542d7ebe22b2be", {
        params: {
          orgId: sessionStorage('userId').getObject('userId').twoLevelOrgId,
          two: true
        }
      }).then((res) => {
        this.secondaryGroupPersionList = res.data.data;
      }).catch(e => {
        this.$Message.error("数据获取失败")
      });
      //集团
      await this.$http.get(Api.queryRoleUser + "/" + "17744170d3c24383bd283fbe72f3d664").then((res) => {
        this.groupPersionList = res.data.data;
      }).catch(e => {
        this.$Message.error("数据获取失败")
      });
      this.spinShow = false;
    },
    downloadFile(guideId, file,index) {
      let url = this.fileUrl + '/file/' + file.id;
      this.uploadListVisible[index] = true;
      var _this = this;
      this.$http.get(url, {
        responseType: 'blob',      //告诉服务器我们需要的响应格式
        progress:function(e){
          _this.$set(_this.uploadListPercent,index, 100 * (e.loaded / e.total));
        }
      }).then((res) => {
        console.log(res)
        const aLink = document.createElement("a");
        let blob = new Blob([res.data], {
          type: res.bodyBlob.type      //将会被放入到blob中的数组内容的MIME类型
        });
        aLink.href = URL.createObjectURL(blob)
        aLink.download = file.fileName //标题
        aLink.click()
        document.body.appendChild(aLink)
      })
    },
    setUserName(data) {
      this.InputData.deptLeaderName = data;
    },
    setUserId(data) {
      this.InputData.deptLeaderId = data[data.length - 1];
    },
    remove1(id) {
      console.log(id)
      let url = this.fileUrl + '/file/' + id;
      this.$http.delete(url).then((res) => {
        this.getFiles()
      })
    },
    beforeUpload(file) {
      console.log(this.uploadList)
      let formData = new FormData();
      formData.append("files", file); // 文件对象
      let url = this.fileUrl + '/' + this.InputData.reportId + '/files/reportFile'
      this.$http.post(url, formData).then((res) => {
        if (res.data.result == "success") {
          this.$Message.info("文件上传成功")
          this.getFiles();
        }
      })
      return false
    },
    getFiles() {
      let url = this.fileUrl + '/' + this.InputData.reportId + '/files/reportFile'
      this.$http.get(url).then((res) => {
        if (res.data.result == "success") {
          this.uploadList = res.data.data
          let index = 0;
          this.uploadList.forEach(item=>{
            this.uploadListPercent[index]=0;
            this.uploadListVisible[index] = false;
            index++;
          })
        }
      })
    },
    showHistory(row) {
      this.model4 = true;
      this.loading2 = true;
      this.$http.get(Api.getHistory + '/' + row.procinstId, {params: {}}).then((res) => {
        this.history = res.data;
        this.loading2 = false;
      }).catch(e => {
        this.$Message.error("数据获取失败")
      })
    },
    danxuan(row, index) {
      this.InputData.contractorId = row.contractorId
      this.InputData.contractorName = row.contractorName
      this.model2 = false
      this.model1 = true
    },
    selectContractor() {
      this.model2 = true
      this.contractor = []
      let data = {
        startPage: this.pageModel2.currentPage,
        size: this.pageModel2.pageSize,
        contractorName: this.pageModel2.contractorName
      }
      data = Object.assign(data);
      let url = Api.interestedPartiesAccountList
      this.$http.get(url, {params: data}).then((res) => {
        console.log(res.data);
        this.contractor = res.data.data.data;
        this.pageModel2.total = res.data.data.totalSize;
      }).catch(e => {
        this.$Message.error("数据获取失败")
      })
    },

    onCancel() {
      this.InputData = {}
      this.model1 = false
      this.model3 = false
      this.query();

    },
    submit(name) {
      this.$refs[name].validate((valid) => {
        if (valid) {
          this.buttonLoading = true
          if (this.add) {
            let url = Api.report
            this.InputData.bsflag = '0'
            this.InputData.createOrgId = sessionStorage('userId').getObject('userId').orgInfo.orgId
            this.InputData.createUserId = sessionStorage('userId').getObject('userId').userId
            this.$http.post(url, this.InputData).then((res) => {
              this.$Message.success('成功');
              this.query()
              this.buttonLoading = false
              this.model1 = false
            }).catch(e => {
              this.$Message.error('请求失败');
            })
          } else {
            let url = Api.report;
            this.InputData.updateUserId = sessionStorage('userId').getObject('userId').userId
            this.InputData.updateOrgId = sessionStorage('userId').getObject('userId').orgInfo.orgId
            this.$http.put(url, this.InputData).then((res) => {
              this.$Message.success('成功');
              this.buttonLoading = false
              this.model1 = false
              this.query()
            }).catch(e => {
              this.$Message.error('请求失败');
            })
          }
        } else {
          this.$Message.error('请填报完整!');
        }
      })

    },
    selectCodingSort() {
      this.$http.get(Api.queryCodeDetailBySortId + '/1000001019', {params: {}}).then((res) => {
        this.injuryLeveList = res.data.data;
      });

      this.$http.get(Api.queryCodeDetailBySortId + '/MEM-000001', {params: {}}).then((res) => {
        this.membershipList = res.data.data;
      });
      this.$http.get(Api.queryCodeDetailBySortId + '/TG-000001', {params: {}}).then((res) => {
        this.locationSurveyList = res.data.data;
      });
      this.$http.get(Api.queryCodeDetailBySortId + '/FM-000001', {params: {}}).then((res) => {
        this.appesaseList = res.data.data;
      });


    },

    deleteData(row) {
      let url = Api.report
      let data = {
        reportId: row.reportId
      };
      this.$http.delete(url, {params: data}).then((res) => {
        this.$Message.success('成功');
        this.query()
      }).catch(e => {
        this.$Message.error("数据获取失败")
      })
    },
    addInfo() {
      let userId = sessionStorage('userId').getObject('userId').userId;
      let userName = sessionStorage('userId').getObject('userId').userName;
      this.uploadList = [];
      this.add = true;
      this.InputData = {
        reportId: this.get_uuid(),
        deptLeaderId: userId,
        deptLeaderName: userName
      };
      this.model1 = true;
    },
    query() {
      this.loading = true;
      let data = {
        startPage: this.pagedata.currentPage,
        size: this.pagedata.pageSize,
        orgId: sessionStorage('userId').getObject('userId').companyId
      };
      this.form1.injuryLevels = "";
      this.form1.memberships = "";

      this.injuryLevels.forEach(item => {

        this.form1.injuryLevels += item + ","
      });
      this.memberships.forEach(item => {

        this.form1.memberships += item + ","
      });
      data = Object.assign(data, JSON.parse(JSON.stringify(this.form1)));
      let url = Api.report
      this.$http.get(url, {params: data}).then((res) => {
        console.log(res.data);
        this.dataTable = res.data.data.data;
        this.pagedata.total = res.data.data.totalSize;
        this.loading = false;
      }).catch(e => {
        this.$Message.error("数据获取失败")
      })
    },
    reset() {
      this.form1 = {
        admittanceOrg: '',
        contractorName: ''
      };
      this.injuryLevels = [];
      this.memberships = [];
      this.pageModel2.currentPage = 1;
      this.pageModel2.contractorName = ''
      this.query();
    },
    pageChange1(pageNum) {
      this.pageModel2.currentPage = pageNum;
      this.selectContractor();
    },
    pageSizeChange1(pageSize) {
      this.pageModel2.pageSize = pageSize;
      this.selectContractor();
    },
    pageChange(pageNum) {
      this.pagedata.currentPage = pageNum;
      this.query();
    },
    pageSizeChange(pageSize) {
      this.pagedata.pageSize = pageSize;
      this.query();
    },
    get_uuid() {
      let s = [];
      let hexDigits = "0123456789abcdef";
      for (let i = 0; i < 36; i++) {
        s[i] = hexDigits.substr(Math.floor(Math.random() * 0x10), 1);
      }
      s[14] = "4";
      s[19] = hexDigits.substr((s[19] & 0x3) | 0x8, 1);
      s[8] = s[13] = s[18] = s[23] = "-";

      let uuid = s.join("");
      let reg = new RegExp("-", "g");
      let a = uuid.replace(reg, "");
      console.log(a);
      return a;
    },

  },
  watch: {
    "model1": function (qw, er) {
      if (qw && this.model1) {
        setTimeout(() => {
          this.$refs.childUser1.setCurrentOrg();
        }, 100)
      } else {
        this.$refs.childUser1.resetCurrentOrg();
      }
    },
  },
}
</script>

<style scoped>
@import '../../../../index.css';

.demo-spin-icon-load {
  animation: ani-demo-spin 1s linear infinite;
}
</style>
